package com.achievo.know.domain.infra.hibernate;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.achievo.know.domain.Faq;
import com.achievo.know.domain.FaqRepository;
import com.dayatang.spring.repository.BaseEntityRepositoryHibernateSpring;

@Repository
public class FaqRepositoryImpl extends
		BaseEntityRepositoryHibernateSpring<Faq, Long> implements FaqRepository {

	public FaqRepositoryImpl() {
		super(Faq.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Faq> listFaq(String fkId,int type,int currentPage, int pageSize) {
		DetachedCriteria c=DetachedCriteria.forClass(Faq.class);
		c.add(Restrictions.eq("from", type));
		c.add(Restrictions.eq("fkId", Long.parseLong(fkId)));
		return getHibernateTemplate().findByCriteria(c);
	}

	@Override
	public void batchDelete(final String[] ids) {
		for(String id:ids){
			Faq f=get(Long.parseLong(id));
			if(f!=null){
				getHibernateTemplate().delete(f);
			}
		}
		
	}
	
	


}
